(add-to-load-path (dirname (dirname (current-filename))))
(use-modules (basket)
             (srfi srfi-1))

(define (random-triangle center radius)
  (map (lambda (x)
         (vec-add center
                  (vec-rotate (make-vec radius 0)
                              (+ (* x (/ tau 3))
                                 (* (random:uniform) (/ tau 3))))))
       (iota 3)))

(define (draw-around center radius)
  (let ((triangle (random-triangle center radius))
        (rect (list (vec-sub center (make-vec radius radius))
                    (vec-add center (make-vec radius radius)))))
    (list
      (poly->path triangle)
      (filter (curry triangle-contains triangle)
              (concatenate (rect->vecss rect 32))))))

(define image
  `(stroke
     ,(map (lambda (v) (draw-around v 1/8))
           (concatenate (rect->vecss '((1/8 . 1/8) (7/8 . 7/8)) 4)))))

(render-cairo-png image 1024 (cadr (program-arguments)))
